var Bmob = require("../../utils/Bmob-2.2.0.min.js")
Bmob.initialize("a25cd3ee1411fbed", "999423");

// pages/history/history.js
Page({

  /**
   * 页面的初始数据 
   */
  data: {
    view: 'WEBVIEW'
  },


  /**
   * 生命周期函数--监听页面加载 
   */
  onLoad: function(options) {
    var that = this;
    //fe2fd75434
    const query = Bmob.Query("Todo");
    query.equalTo("userId", "==", wx.getStorageSync("usedata").useId);
    query.equalTo("status", "==", true);
    query.find().then(res => {
      that.setData({
        datas: res
      })
      console.log(res)
    });

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  clear: function() {
    var that = this
    var userId = wx.getStorageSync("usedata").useId
    var status = true
    const query = Bmob.Query('Todo');
    query.equalTo("userId", "==", wx.getStorageSync("usedata").useId);
    query.equalTo("status", "==", true);
    query.find().then(todos => {
      todos.destroyAll().then(res => {
        console.log(res, 'ok')
        that.setData({
          datas: []
        })
      }).catch(err => {
        console.log(err)
      });
    })
  }
})